package com.qingzhuge.member.controller;

import com.qingzhuge.controller.base.AbstractController;
import com.qingzhuge.dto.response.ResponseBodyDto;
import com.qingzhuge.member.dto.request.SysFeedbackRequestDto;
import com.qingzhuge.member.dto.response.SysFeedbackResponseDto;
import com.qingzhuge.member.entity.SysFeedback;
import com.qingzhuge.member.service.ISysFeedbackService;
import com.qingzhuge.utils.PageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static com.qingzhuge.common.Constants.Controller.PATH_BY_ID;
import static com.qingzhuge.common.Constants.Controller.PATH_PAGE;

/**
 * @author : zero.xiao
 * @description :
 * @date : 2018/9/25 0025 下午 17:36
 * @modified :
 * @since :
 */
@RestController
@RequestMapping("/api/auth/user/feedback")
@Api(tags = "A用户反馈")
public class ApiSysFeedbackController extends AbstractController {
    @Resource
    private ISysFeedbackService service;

    @ApiOperation(value = "前端分页")
    @PutMapping(PATH_PAGE)
    public ResponseEntity<ResponseBodyDto<PageUtil<SysFeedbackResponseDto>>> query(@RequestBody(required = false) SysFeedbackRequestDto requestDto) {
        SysFeedback feedback = service.dto2Bean(requestDto);
        PageUtil<SysFeedback> page = service.query(feedback);
        return returnSuccess(page, SysFeedbackResponseDto.class);
    }

    @ApiOperation(value = "详情")
    @GetMapping(PATH_BY_ID)
    public ResponseEntity<ResponseBodyDto<SysFeedbackResponseDto>> get(@PathVariable Long id) {
        SysFeedback feedback = service.findById(id);
        return returnSuccess(feedback, SysFeedbackResponseDto.class);
    }

    @ApiOperation(value = "提交反馈")
    @PostMapping
    public ResponseEntity<ResponseBodyDto<SysFeedbackResponseDto>> update(@RequestBody SysFeedbackRequestDto requestDto) {
        SysFeedback feedback = service.dto2Bean(requestDto);
        feedback = service.save(feedback);
        return returnSuccess(feedback, SysFeedbackResponseDto.class);
    }

    @ApiOperation(value = "删除反馈")
    @DeleteMapping(PATH_BY_ID)
    public ResponseEntity<ResponseBodyDto<Object>> delete(@PathVariable Long id) {
        service.deleteById(id);
        return returnSuccess();
    }
}
